import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;


//Creating JFrame
public class MyFrame extends JFrame {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 8904641527445622030L;
	/**
	 * The default width for text fields and text areas.
	 */
	private static final int TEXT_WIDTH = 20;
	
	
	private static JFrame my_confFrame;
    private static final JPanel my_input_panel = new JPanel();
	private static final JTextField my_nameText = new JTextField(TEXT_WIDTH);
	
	public  MyFrame() throws IOException {
		my_confFrame = new JFrame();
		my_confFrame.setSize(1360, 760);
		my_confFrame.setTitle("Conferences for the Multinational Society for Engineering Education");
		// read image file in my HardDisk using imageIO and assign it to buffered image reference 
		URL url = getClass().getResource("/Images/Conference.jpg");
		BufferedImage bf = ImageIO.read(url);
	
		// adding created component to the JFrame using background image  class
		my_confFrame.setContentPane(new BackgroundImageFrame(bf));
		 
	
		// Menu
		final JMenuBar mb = new JMenuBar(); // Menu bar
		final JMenu mnuLogin = new JMenu("Login"); // File Entry on Menu bar
		final JMenuItem mnuItemLogin = new JMenuItem("Login"); // Quit sub item
		final JMenuItem mnuItemQuit = new JMenuItem("Quit"); // Quit sub item
	
		
		final JMenu mnuHelp = new JMenu("Help"); // Help Menu entry
		final JMenuItem mnuItemAbout = new JMenuItem("About"); // About Entry
	
		// Set menu bar
		my_confFrame.setJMenuBar(mb);
		//Build Menus
		mnuLogin.add(mnuItemLogin); // Create Quit line
		mnuLogin.add(mnuItemQuit); // Create Quit line
		mnuHelp.add(mnuItemAbout); // Create About line
		mb.add(mnuLogin); // Add Menu items to form
		mb.add(mnuHelp);
	 
	    final JLabel input_label = new JLabel("Please enter you name: ");
		final JButton submitButton = new JButton("Submit"); 

	    my_input_panel.add(input_label);
	    my_input_panel.add(my_nameText);
	    my_input_panel.add(submitButton);
		
	    my_confFrame.setLayout(new BorderLayout());
		
		//Add Menu listener
		mnuItemLogin.addActionListener(new ListenMenuLogin());
		mnuItemQuit.addActionListener(new ListenMenuQuit());
		mnuItemAbout.addActionListener(new ListenMenuAbout());

		submitButton.addActionListener(new submitListener());
		// Allows the Swing App to be closed
		my_confFrame.addWindowListener(new ListenCloseWdw());
		
		my_confFrame.setVisible(true);
	}

	private class submitListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
		     final String name = my_nameText.getText();
		      if (name.length() == 0)
		      {
		        JOptionPane.showMessageDialog(my_confFrame, "You must enter a name!");
		      }
		      else if(name != "found")
		      {
		    	  
		    	  int n = JOptionPane.showConfirmDialog(
		    	            null, "Would you like to register?",
		    	            "Name Not found!",
		    	            JOptionPane.YES_NO_OPTION);

		    	  if(n == 0){
		    	            JOptionPane.showMessageDialog(null, "HELLO");
		    	  }else {
		    	    JOptionPane.showMessageDialog(null, "GOODBYE");
		    	  }  
					    		
		        my_nameText.setText(null); // clears input field
		      }else{
		    	  // load appropriate panel option to BorderLayout.NORTH
		      }
		      my_nameText.grabFocus();
		}
	}
	
	private class ListenMenuAbout implements ActionListener{
		public void actionPerformed(ActionEvent e){
			JOptionPane.showMessageDialog(my_confFrame, 
					"This is the official Multinational Society for Engineering Education" +
					"conference website.");
		}
	}	
	
	private class ListenMenuLogin implements ActionListener{
		public void actionPerformed(ActionEvent e){
			my_confFrame.add(my_input_panel, BorderLayout.NORTH);
			my_confFrame.setVisible(true);
		}
	}	
	private class ListenMenuQuit implements ActionListener{
		public void actionPerformed(ActionEvent e){
			System.exit(0);
		}
	}
	
	private class ListenCloseWdw extends WindowAdapter{
		public void windowClosing(WindowEvent e){
			System.exit(0);
		}
	}
	
	
	
	
	
	
	 
	public static void main(String[] args) throws IOException {
	 
		MyFrame f = new MyFrame();
		 
		//f.setVisible(true);
	}
	 
}